package testApplets;

import java.util.ArrayList;

import processing.core.PApplet;
import simpleGeom.Mesh;
import simpleGeom.MeshNode;
import simpleGeom.Vec3D;

public class RemovePeaksApplet extends PApplet {
Mesh mesh;
public void setup(){
	mesh=new Mesh();
	mesh.loadMesh(this.selectInput());
	mesh.construct();
	
	for (int i=0;i<mesh.getNNodes();i++){
		MeshNode node=mesh.getNode(i);
		if (node.x==0&&node.y==0&&node.z==0){
			
			MeshNode[] nbs=node.getNbs();
			println("here we are: "+nbs.length);
			Vec3D center=new Vec3D();
			ArrayList<MeshNode>allNbs=new ArrayList<MeshNode>();
			for (int j=0;j<nbs.length;j++){
				MeshNode cNode=nbs[j];
				MeshNode[] nbs2=cNode.getNbs();
				for (int jj=0;jj<nbs2.length;jj++){
					MeshNode n=nbs2[jj];
					if (n.x!=0||n.y!=0||n.z!=0){
						allNbs.add(n);
						center.add(n);
					}
				}
			}
			
			center.mult(1f/allNbs.size());
			
			node.setPosition(center.x, center.y, center.z);
			println(node);
		}
	}
	mesh.saveMesh(this.selectOutput());
}
}
